#include "GameObject.h"
#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H

GameObject::GameObject(SDL_Surface * img, Point pos)
{
	position.x = pos.x;
	position.y = pos.y;
	image = img;
	bound.x = pos.x;
	bound.y = pos.y;
	bound.w = img->w;
	bound.h = img->h;
}

GameObject::~GameObject()
{
//	SDL_FreeSurface(image);
}

void GameObject::Update()
{
		bound.x = position.x;
		bound.y = position.y;
}
SDL_Rect GameObject::getBox()
{
	bound.x = position.x;
	bound.y = position.y;
	bound.w = this->image->w;
	bound.h = this->image->h;
	return bound;
}

void GameObject::SetPosition(Point pos)
{
	position.x = pos.x;
	position.y = pos.y;
}
void GameObject::Move(int dx, int dy)
{
	position.x += dx;
	position.y += dy;

	if (position.x > WITCH -image->clip_rect.w)
	{
		position.x = WITCH -image->clip_rect.w;
	}
	else if (position.x < 0)
	{
		position.x = 0;
	}

}
void GameObject::Draw(SDL_Surface*screen)
{
	SDL_BlitSurface(this->image, NULL, screen, &bound);
}
bool GameObject::checkCollision(SDL_Rect A, SDL_Rect B)
{
	int leftA, leftB;
	int rightA, rightB;
	int topA, topB;
	int botA, botB;

	leftA = A.x;
	rightA = A.x + A.w;
	topA = A.y;
	botA = A.y + A.h;

	leftB = B.x;
	rightB = B.x + B.w;
	topB = B.y;
	botB = B.y + B.h;

	if (botA >  topB &&  rightA <= rightB && leftA >= leftB)
	{
		return true;
	}
	else return false;
}
#endif